package com.jcl.recruit.elasticsearch.resume.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.elasticsearch.resume.dao.SearchResumeProjectDao;
import com.jcl.recruit.elasticsearch.resume.model.SearchResumeProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SearchResumeProjectLogic
 * @Author yyliu
 * @Date 2018/11/13 10:37
 * @Version 1.0
 **/
@Component
public class SearchResumeProjectLogic {

    @Autowired
    private SearchResumeProjectDao searchResumeProjectDao;

    public Map<Integer, List<SearchResumeProject>> findListByResumeMap(List<Integer> resumeIds) {

        Map<Integer, List<SearchResumeProject>> dataMap = new HashMap<>();
        List<SearchResumeProject> list = searchResumeProjectDao.findListByResumeIds(resumeIds);
        if (CollectionUtils.isNotEmpty(list)) {
            for (SearchResumeProject entity : list) {
                List<SearchResumeProject> entityList = dataMap.get(entity.getResumeId());
                if (null == entityList) {
                    entityList = new ArrayList<>();
                    dataMap.put(entity.getResumeId(), entityList);
                }
                entityList.add(entity);
            }
        }
        return dataMap;
    }

    public List<SearchResumeProject> findListByResumeIds(List<Integer> resumeIds) {
        return searchResumeProjectDao.findListByResumeIds(resumeIds);
    }

    public List<Map<String, Object>> findObjListByResumeId(Integer id) {
        return searchResumeProjectDao.findObjListByResumeId(id);
    }

    public List<SearchResumeProject> findListByResumeId(Integer id) {
        return searchResumeProjectDao.findListByResumeId(id);
    }

    public int batchInsert(List<SearchResumeProject> list) {
        return searchResumeProjectDao.batchInsert(list);
    }

    public int batchDeleteByResumeIds(List<Integer> ids) {
        return searchResumeProjectDao.batchDeleteByResumeIds(ids);
    }
}
